找传奇、传世资源到传世资源站!

android百度地图开发简单Demo

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

android百度地图开发简单Demo
android百度地图开发简单Demo
public class MainActivity extends Activity implements OnGetGeoCoderResultListener { public static final String ROUTE_PLAN_NODE = "routePlanNode"; /** * 全局变量 */ private static final String APP_FOLDER_NAME = "lbstest"; //appSD卡中的目录名 public static List<Activity> activityList = new LinkedList<>(); private final String TTS_API_KEY = "9825418"; //语音播报api_key boolean isFirstLoc = true; //是否首次定位 GeoCoder mSearch = null; //地理编码模块 String authinfo = null; /** * UI相关 */ private RelativeLayout popuInfoView = null; //点击marker后弹出的窗口 private AutoCompleteTextView autoCompleteTextView = null; //输入搜索关键字的view private ArrayAdapter<String> adapter = null; //适配器,展示搜索结果 private Button searchBtn = null; //搜索按钮 private Button goButton = null; //到这去 按钮 private String mSDCardPath = null; /** * 百度地图相关 */ private LocationClient locationClient; //定位SDK核心类 private MapView mapView; //百度地图控件 private BaiduMap baiduMap; //百度地图对象 private LatLng myLocation; //当前定位信息 private LatLng clickLocation; //长按地址信息 private BDLocation currentLocation; //当前定位信息[最好使用这个] private PoiSearch poiSearch; //POI搜索模块 private SuggestionSearch suggestionSearch = null; //模糊搜索模块 private MySensorEventListener mySensorEventListener; //传感器 private float lastX = 0.0f; //传感器返回的方向 private boolean initSuccess = false; //初始化标志位 private boolean initDir = false; /** * 内部TTS播报状态回传handler */ private Handler ttsHandler = new Handler() { public void handleMessage(Message msg) { int type = msg.what; switch (type) { case BaiduNaviManager.TTSPlayMsgType.PLAY_START_MSG: { //showToastMsg("Handler : TTS play start"); break; } case BaiduNaviManager.TTSPlayMsgType.PLAY_END_MSG: { //showToastMsg("Handler : TTS play end"); break; } default: break; } } }; /** * 内部TTS播报状态回调接口 */ private BaiduNaviManager.TTSPlayStateListener ttsPlayStateListener = new BaiduNaviManager.TTSPlayStateListener() { @Override public void playEnd() { showToastMsg("TTSPlayStateListener : TTS play end"); } @Override public void playStart() { showToastMsg("TTSPlayStateListener : TTS play start"); } }; private BNOuterTTSPlayerCallback mTTSCallback = new BNOuterTTSPlayerCallback() { @Override public void stopTTS() { // TODO Auto-generated method stub Log.e("test_TTS", "stopTTS"); } @Override public void resumeTTS() { // TODO Auto-generated method stub Log.e("test_TTS", "resumeTTS"); } @Override public void releaseTTSPlayer() { // TODO Auto-generated method stub Log.e("test_TTS", "releaseTTSPlayer"); } @Override public int playTTSText(String speech, int bPreempt) { // TODO Auto-generated method stub Log.e("test_TTS", "playTTSText" "_" speech "_" bPreempt); return 1; } @Override public void phoneHangUp() { // TODO Auto-generated method stub Log.e("test_TTS", "phoneHangUp"); } @Override public void phoneCalling() { // TODO Auto-generated method stub Log.e("test_TTS", "phoneCalling"); } @Override public void pauseTTS() { // TODO Auto-generated method stub Log.e("test_TTS", "pauseTTS"); } @Override public void initTTSPlayer() { // TODO Auto-generated method stub Log.e("test_TTS", "initTTSPlayer"); } @Override public int getTTSState() { // TODO Auto-generated method stub Log.e("test_TTS", "getTTSState"); return 1; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_main); //界面初始化:控件初始化 initView(); //初始化百度地图相关 initBaiduMap(); //初始化传感器 initSensor(); } /** * 初始化传感器 */ private void initSensor() { //方向传感器监听 mySensorEventListener = new MySensorEventListener(this); //增加监听:orientation listener mySensorEventListener.setOnOrientationListener(new MySensorEventListener.OnOrientationListener() { @Override public void onOrientationChanged(float x) { //将获取的x轴方向赋值给全局变量 lastX = x; } }); //开启监听 mySensorEventListener.start(); } /** * 初始化百度地图相关模块 */ private void initBaiduMap() { /***************************************************** * 地图模块 *****************************************************/ //百度地图map baiduMap = mapView.getMap(); //增加监听:Marker click listener baiduMap.setOnMarkerClickListener(new OnMarkerClickListener()); /***************************************************** * 定位模块 *****************************************************/ // 开启定位图层 baiduMap.setMyLocationEnabled(true); //定位服务客户端 locationClient = new LocationClient(this); //注册监听 locationClient.registerLocationListener(new MyLocationListenner()); //定位配置信息 LocationClientOption option = new LocationClientOption(); // 打开gps option.setOpenGps(true); // 设置坐标类型,国测局经纬度坐标系:gcj02; 百度墨卡托坐标系:bd09; 百度经纬度坐标系:bd09ll option.setCoorType("bd09ll"); //定位请求时间间隔 1 option.setScanSpan(1000); //设备方向 option.setNeedDeviceDirect(true); //是否需要地址信息 option.setIsNeedAddress(true); //是否需要地址语义化信息 option.setIsNeedLocationDescribe(true); locationClient.setLocOption(option); //开启定位 locationClient.start(); //定位模式 baiduMap .setMyLocationConfigeration(new MyLocationConfiguration( MyLocationConfiguration.LocationMode.NORMAL, true, null)); //增加监听:长按地图 baiduMap.setOnMapLongClickListener(new OnMapLongClickListener()); //增加监听:map click listener ,主要监听poi点击 baiduMap.setOnMapClickListener(new OnMapClickListener()); /****************************************************** * 地理编码模块 ******************************************************/ //地理编码模块 mSearch = GeoCoder.newInstance(); //增加监听:地理编码查询结果 mSearch.setOnGetGeoCodeResultListener(this); /****************************************************** * POI搜索模块 ******************************************************/ //POI搜索模块 poiSearch = PoiSearch.newInstance(); //增加监听:POI搜索结果 poiSearch.setOnGetPoiSearchResultListener(new PoiSearchListener()); //模糊搜索 suggestionSearch = SuggestionSearch.newInstance(); //增加监听:模糊搜索查询结果 suggestionSearch.setOnGetSuggestionResultListener(new SuggestionResultListener()); /*** * 导航模块需要的初始化 */ initDir = initDirs(); initNavi(); } /** * 界面初始化 **/ private void initView() { //关键字输入view autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView); //增加监听:text change listener autoCompleteTextView.addTextChangedListener(new TextViewWatcher()); //搜索btn searchBtn = (Button) findViewById(R.id.searchBtn); //增加监听 searchBtn.setOnClickListener(new OnClickListener()); //百度地图view mapView = (MapView) findViewById(R.id.bmapView); //到这去 按钮 goButton = (Button) findViewById(R.id.go_button); }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复